const getParameter = name => {
    const str = window.location.search;
    let index = str.indexOf("?" + name + "=");
    if (index === -1) {
        index = str.indexOf("&" + name + "=");
    }
    if (index === -1) {
        return null;
    }
    let end = str.indexOf("&", index + 1);
    if (end === -1) {
        return str.substring(index + 2 + name.length);
    } else {
        return str.substring(index + 2 + name.length, end);
    }
};
/**
 * 存储localStorage
 */
const setStore = (name, content) => {
    if (!name) return;
    if (typeof content !== 'string') {
        content = JSON.stringify(content);
    }
    window.localStorage.setItem(name, content);
};

/**
 * 获取localStorage
 */
const getStore = name => {
    if (!name) return;
    return window.localStorage.getItem(name);
};

/**
 * 删除localStorage
 */
const removeStore = name => {
    if (!name) return;
    window.localStorage.removeItem(name);
};
//当前系统（Android，ios）
const system = (() => {
    let u = navigator.userAgent;
    let isAndroid = u.indexOf('Android') > -1 || u.indexOf('Linux') > -1; //android;
    let isIOS = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/); //ios;
    let system;
    if (isAndroid) {
        system = 'android'
    } else if (isIOS) {
        system = 'ios'
    }
    return system
})();
//当前web环境（微信，h5，pc）
const env = (() => {
    let u = navigator.userAgent;
    let isWeixin = (u.toLowerCase().match(/MicroMessenger/i));//weixin;
    let env;
    if (isWeixin) {
        env = 'weixin'
    } else if (u.match(/Android/i)
        || u.match(/webOS/i)
        || u.match(/iPhone/i)
        || u.match(/iPad/i)
        || u.match(/iPod/i)
        || u.match(/BlackBerry/i)
        || u.match(/Windows Phone/i)) {
        env = 'h5'
    } else {
        env = 'pc'
    }
    return env
})();

export {getParameter, setStore, getStore, removeStore, system, env}
